package br.com.canvasForAll.ws.resource;

import java.util.Collection;

import javax.ejb.EJB;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response.Status;

import br.com.canvasForAll.model.entity.Comentario;
import br.com.canvasForAll.model.entity.Postit;
import br.com.canvasForAll.model.services.interfaces.ComentarioService;
import br.com.canvasForAll.model.services.interfaces.PostitService;

@Path("comentario")
public class ComentarioWS {
	
	@EJB private PostitService postitService;
	@EJB private ComentarioService comentarioService;
	
	@GET
	@Path("/comentariosPostit/{id_postit}")
	@Produces(MediaType.APPLICATION_JSON)
	public Collection<Comentario> getComentarioPostit(@PathParam("id_postit") String idPostit) throws Exception {
		try{
			Long id = new Long(idPostit);
			Postit postit = postitService.obterPorId(id);
			Collection<Comentario> comentarios = comentarioService.obterComentarioPorPostit(postit);
			return comentarios;

		} catch (Exception e) {
			e.printStackTrace();
			throw new WebApplicationException(Status.NOT_FOUND);
		}
	}

}
